package cn.janescott.eurekaclient.web;

import cn.janescott.eurekaclient.configuration.ConfigServerProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author scott
 * @date 2019/1/3
 */
@RestController
@RefreshScope
@RequestMapping("/query")
public class QueryController {

    @Resource
    private EurekaClientConfigBean clientConfigBean;

    @Resource
    private ConfigServerProperties configServerProperties;

    @Resource
    private Environment environment;

    @GetMapping("/getEurekaServerUrl")
    public Object getEurekaServerUrl() {
        return clientConfigBean.getServiceUrl();
    }

    @GetMapping("/getEurekaInfo")
    public String getEurekaInfo() {
        return environment.getProperty("app.ip") + ":" + environment.getProperty("server.port");
    }

    @GetMapping("/getConfig")
    public Object getConfig() {
        return configServerProperties.getName();
    }
}
